<?php
#
#
# Copyright TEDECO, 2009. http://tedeco.fi.upm.es
#
# This file is part of kumenya.
#
# Kumenya is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Kumenya is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
#
#
#
?>
<?php
	Interfaz::CheckSession(Accountant);

	$showMessage = FALSE;
	$showData = 0;
	$TransactionUid = Interfaz::Data(Uid . TransactionsTable);
	$origin = Interfaz::OriginPage(FALSE);

	$action = Interfaz::ObjectType ();

	if ($action != "Details")
		$transactionData = array_merge (array (Uid . TransactionsTable=> $TransactionUid), Interfaz::RecordedData());

	$recordedData = Interfaz::RecordedData();
	$goBackData = array (StartDate => $recordedData[StartDate], EndDate => $recordedData[EndDate]);

	if ($action == Entry) {
		include(Action . "NewEntry.php");
		if ($result) {
			$message = Interfaz::Result();
			$showMessage = TRUE;
			$showData = 1;
		}
	}
	else if ($action == "Details") {
		$TransactionUid = Interfaz::Data(Uid);
		$transactionData = Transaction::SeeDetails(Interfaz::Data());

		if (is_array ($transactionData)) {
			$transactionData = array_merge ($transactionData, array (Uid . TransactionsTable => $TransactionUid));
			$record = array_merge ($transactionData, Interfaz::RecordedData());
			Interfaz::Session (Record, $record, FALSE);
	
			$result = TRUE;
			$showData = 1;
		}
		else {
			$result = FALSE;
			Interfaz::Error("Transaction not found");
		}
	}
	else if ($action == "Entry") {
		include(Action . "EntryDetails.php");		
		$data = array_merge ($transactionData, $data);
		$showData = 2;
		$result = TRUE;
	}
	else if ($action == "Cancel") {
		include(Action . "EntryCancelation.php");
		if ($result) {
			$message = Interfaz::Result();
			$showMessage = TRUE;
			$showData = 1;
		}		
	}
	else if ($action == "Modify") {
		include(Action . "EntryModification.php");
		if ($result) {
			$message = Interfaz::Result();
			$showMessage = TRUE;
			$showData = 1;
		}		
	}
	else if ($action == Transaction) {
		include(Action . "TransactionModificationResult.php");
		if ($result) {
			$message = Interfaz::Result();
			$showMessage = TRUE;
			$showData = 1;
			$TransactionUid = Interfaz::Data(Uid);
			$transactionData = array_merge (array (Uid . TransactionsTable=> $TransactionUid), Interfaz::RecordedData());
		}
	}
	else
		$result = TRUE;
		
	if ($result) {
		$criterias = array (Uid => $TransactionUid);

		$table = Transaction::SearchNotes($criterias);

		if ($table !== FALSE) {
			if (Interfaz::Data(Uid . TransactionsTable)) {
				$total = Transaction::CheckTotal (Interfaz::Data());
			}
			else {
				$total = Transaction::CheckTotal (array (Uid . TransactionsTable => $TransactionUid));
			}
				
			$result = TRUE;
		}
		else {
			// ENTRIES NOT FOUND
			Interfaz::FreeObject();
			$result = FALSE;
		}
	}
	else {
		// ENTRY NOT CREATED
		Interfaz::FreeObject();
		$result = FALSE;
	}
?>